//
//  LVEditHeadPortraitCell.m
//  LEVE
//
//  Created by 上官惠阳 on 2017/3/1.
//  Copyright © 2017年 dashuju. All rights reserved.
//

#import "LVEditHeadPortraitCell.h"
#import "LVHeadProtraitCell.h"

#define itemWidth 50
@interface LVEditHeadPortraitCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@end
@implementation LVEditHeadPortraitCell
{
    NSIndexPath *_seletedIndexPath;
}
- (void)awakeFromNib {
    [super awakeFromNib];

    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [_collectionView registerNib:[UINib nibWithNibName:@"LVHeadProtraitCell" bundle:nil] forCellWithReuseIdentifier:@"LVHeadProtraitCell"];

    _dataSource = [[NSMutableArray alloc] init];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    [self makeUI];
}
- (void)makeUI
{

}
#pragma mark UICollectionDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return  32;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LVHeadProtraitCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LVHeadProtraitCell" forIndexPath:indexPath];
    cell.seletedView.hidden = !(_seletedIndexPath && indexPath.row == _seletedIndexPath.row);
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(itemWidth, itemWidth);
}
#pragma mark UICollectionDelegate
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (_seletedIndexPath == indexPath) {
        _seletedIndexPath = nil;
    }else{
        _seletedIndexPath = indexPath;
    }

    [_collectionView reloadData];
}
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
@end
